home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / CPU_MEMO / 0978.ZIP / TERM.ASM < prev    next >
Assembly Source File  |  1986-05-31  |  3KB  |  149 lines

  1.         name    term
  2.         page    ,132
  3.  
  4.         title    Resident Program Termination Routine
  5.  
  6. comment        \
  7.  
  8.         This program gives users a last ditch way to get a program
  9.         to peacefully terminate.  It ties into the user timer
  10.         interrupt, and checks the shift flags to see if it should
  11.         activate.  If so, it prints a message and issues a DOS
  12.         function call 4c, with return code 255.
  13.  
  14.         \
  15.  
  16. dos_data    segment at 40h
  17.         org    17h
  18. KB_FLAG        label    byte    ; dangerous hardwired location
  19. dos_data    ends
  20.  
  21. code        segment
  22.         org    100h            ;For COM conversion
  23.  
  24.         assume    cs:code, ds:code
  25.  
  26. DOS_entry    label    far            ;DOS entry point
  27.         jmp    install
  28.  
  29. old_timer    dd    ?            ;Old timer interrupt
  30. guard        dw    0
  31. debounce    db    0
  32.  
  33. msg1        db    0dh, 0ah, 7, ' Issuing termination request'
  34.         db    0dh, 0ah, 0, '$'
  35.  
  36. RIGHT_SHIFT    equ    01h
  37. LEFT_SHIFT    equ    02h
  38. CTL_SHIFT    equ    04h
  39. ALT_SHIFT    equ    08H
  40.  
  41. TRIGGER        equ    ALT_SHIFT or LEFT_SHIFT or RIGHT_SHIFT or CTL_SHIFT
  42.  
  43. timer        proc    far
  44.         sti
  45.         push     cx
  46.         mov    cx, cs:guard
  47.         jcxz    chk_kybd        ; ensure guard is clear
  48.         pop    cx            ; otherwise go home
  49.         jmp    cs: old_timer
  50.  
  51. chk_kybd:    push     ds            ; check for the trigger
  52.         push    ax
  53.         mov    ax, dos_data
  54.         mov    ds, ax
  55.         assume    ds:dos_data
  56.         mov    al, KB_FLAG
  57.         and    al, TRIGGER
  58.         push    cs
  59.         pop    ds
  60.         assume    ds:code            ; al == trigger if set
  61.         mov    ah, debounce
  62.         or    ah, ah
  63.         jnz    do_debounce        ; take care of debouncing
  64.         cmp    al, TRIGGER
  65.         jne    go_home
  66.  
  67. do_term:    mov    guard, -1        ; this is it!
  68.         push    si
  69.         mov    si, offset msg1
  70.         call    write_tty
  71.         pop    si
  72.         mov    debounce, -1
  73.  
  74. ;        mov    guard, 0        ; for debugging: do everything
  75. ;        jmp    go_home            ; except the terminate
  76.  
  77.         mov    al, 020h
  78.         out    020h, al        ; make the 8259 happy
  79.  
  80.         mov    ah, 4ch
  81.         mov    al, -1
  82.         mov    guard, 0
  83.         int    21h            ; terminate process
  84.  
  85. do_debounce:    cmp    al, TRIGGER        ; is trigger still on?
  86.         je    go_home
  87.         mov    debounce, 0
  88.  
  89. go_home:    pop    ax            ; no trigger, go home
  90.         pop    ds
  91.         pop    cx
  92.         jmp    cs:old_timer
  93. timer        endp
  94.  
  95. ; write a null terminated string indexed by DS:SI
  96. write_tty    proc    near
  97.         lodsb
  98.         or    al, al
  99.         jz    wt1
  100.         mov    ah, 0eh
  101.         int    10h
  102.         jmp    write_tty
  103. wt1:        ret
  104. write_tty    endp
  105.  
  106. comment        \
  107.  
  108.         Everything past this point will be reclaimed when the install
  109.         procedure returns to DOS after the program is first run.
  110.  
  111.         \
  112.  
  113. greeting    db    13,10
  114.         db    218,32 dup (196),191,13,10
  115.         db    179,'  Termination Routine has been  ',179,13,10
  116.         db    179,'        installed in RAM        ',179,13,10
  117.         db    192,32 dup (196),217,13,10,0,'$'
  118.  
  119. comment        \
  120.  
  121.         The install procedure is invoked through the DOS entry point
  122.         when the program is first run. It installs the new interrupt
  123.         and prints a message on the console. When done, it returns to
  124.         DOS and allows the space it occupies itself to be reclaimed.
  125.  
  126.         \
  127.  
  128.         assume    cs:code
  129.  
  130. install        proc    near
  131.         push    cs                ;Set DS up for
  132.         pop    ds                ;   interrupt replace
  133.         mov    ax, 351ch            ; user timer.
  134.         int    21h
  135.         mov    word ptr old_timer, bx
  136.         mov    word ptr old_timer+2, es
  137.         mov    dx, offset timer
  138.         mov    ax, 251ch
  139.         int    21h
  140.         mov    dx, offset greeting
  141.         mov    si, dx
  142.         call    write_tty
  143.         int    27h                ;Terminate & stay res
  144. install        endp
  145.  
  146. code        ends
  147.         end    DOS_entry            ;Must be far label
  148.  
  149.